package edu.ynu.se.xiecheng.achitectureclass.controller;


import edu.ynu.se.xiecheng.achitectureclass.entity.User;
import edu.ynu.se.xiecheng.achitectureclass.entity.vo.Result;
import edu.ynu.se.xiecheng.achitectureclass.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author laruui
 * @since 2023-12-07
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    public UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        log.info(user.toString());
        user.setAccount(user.getUsername());
        return userService.login(user);
    }

    @PostMapping("/logout")
    public Result logout() {
        return userService.logout();
    }

    /**
     * 登录成功获取管理员信息
     *
     * @return 管理员信息
     */
    @GetMapping("/info")
    public Result getUserInfo(String token) {
        return userService.getLoginUserInfo(token);
    }

}


